<script type="text/javascript" src="/js/swfupload2.2.0/swfupload.js" charset="utf-8"></script>
<script type="text/javascript" src="/js/swfupload2.2.0/handlers.js" charset="utf-8"></script>
<script type="text/javascript" src="/js/swfupload2.2.0/fileprogress.js" charset="utf-8"></script>
<script type="text/javascript" src="/js/swfupload2.2.0/swfupload.queue.js" charset="utf-8"></script>
<style>
#logList { margin: 0; padding: 0; width: 500px }    
#logList li { list-style-position: inside; margin: 2px; border: 1px solid #ccc; padding: 10px; color: #333;  
            font-size: 15px; background: #FFF; position: relative; }    
#logList li .progressBar { border:1px solid #333; height:5px; background:#fff; }      
#logList li .progressValue { color: red; margin-left: 5px }      
#logList li .progress { background:#999; width:0%; height:5px; }      
#logList li p { margin:0; line-height:18px; }      
#logList li.success { border:1px solid #339933; background:#ccf9b9; }    
</style>
<script>
	var swfu_;
	var queueErrorArray; 
	$(function(){
	var btn = $("#upbtn").get(0);
    swfu_= new SWFUpload({
			upload_url: "/upload/upload",
			post_params : {
	           "bizType" : "OTHER",
	           "fileType" : "NORMAL",
	           "fileName" : ""
		    },
		    
		 // Flash Settings
			flash_url : "/js/swfupload2.2.0"+"/swfupload.swf",
		    
            file_post_name: "filedata",
            file_size_limit:"200MB",
			file_types : "*.apk",
			file_types_description : "Android安装包",
			file_upload_limit :1,
			
			// handlers  
	        file_dialog_start_handler: fileDialogStart,  
	        file_queued_handler: fileQueued,  
	        file_queue_error_handler: fileQueueError,  
	        file_dialog_complete_handler: fileDialogComplete,  
	        upload_start_handler: uploadStart,  
	        upload_progress_handler: uploadProgress,  
			upload_success_handler : function(f,data){
				eval("var json="+data+";");
				if(json.message=="Success!"){
					var htmstr="";
					htmstr+="<div style='float:left;'><br/><br/>";
					htmstr+='<input type="hidden" name="clientVersion.download_url" value="'+json.data.urls+'">';
					htmstr+=''+json.data.urls+'';
					//htmstr+='<br/><br/><a href="#" class="easyui-linkbutton" onclick="javascript:$(this).parent().remove();">删除</a>';
					htmstr+='<br/><br/> 上传完成!';
					htmstr+='</div>';
					$("#img_div").append(htmstr);
					/*$('.easyui-linkbutton').linkbutton({    
					    iconCls: 'icon-remove'
					}); */
					$("#logList li#SWFUpload_0_0").css('display','none');
					/*var item = $("#logList li#SWFUpload_0_0");  
				    item.find('div.progress').css('width','100%');  
				    item.find('span.progressValue').css('color','blue').text('100%');  
				      
				    item.addClass('success').find('p.status').html('上传完成!'); */ 
				    //alert("=++++"+item);
				    
				}else{
					$.messager.alert('警告','文件上传出错');
				}
			},
			upload_complete_handler : uploadComplete,
			// Button Settings
			button_placeholder_id:"upbtn",
			button_image_url : "/img/SmallSpyGlassWithTransperancy_17x18.png",
			button_width: 80,
			button_height: 18,
			button_text : '<span class="button">上传文件</span>',
			button_text_style : '.button {font-size: 12pt; }',
			button_text_top_padding: 0,
			button_text_left_padding: 18,
			button_disabled : false,
			button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
			button_cursor: SWFUpload.CURSOR.HAND,
			
			custom_settings : {
			//	upload_target : "divFileProgressContainer",
				/*thumbnail_height: 500,
				thumbnail_width: 500,
				thumbnail_quality: 100*/
			},
			debug: true
		});
    
  //========================================  回调函数Handlers  ===================================  
    
    /** 
    * 打开文件选择对话框时响应 
    */  
    function fileDialogStart() {  
        if (queueErrorArray) {  
            queueErrorArray = null;  
        }  
    }  
      
    /** 
    * 文件被加入上传队列时的回调函数,增加文件信息到列表并自动开始上传.<br /> 
    * <p></p> 
    * SWFUpload.startUpload(file_id)方法导致指定文件开始上传, 
    * 如果参数为空,则默认上传队列第一个文件;<br /> 
    * SWFUpload.cancelUpload(file_id,trigger_error_event)取消指定文件上传并从队列删除, 
    * 如果file_id为空,则删除队列第一个文件,trigger_error_event表示是否触发uploadError事件. 
    * @param file 加入队列的文件 
    */  
    function fileQueued(file) {  
        var swfUpload = this;  
        var listItem = '<li id="' + file.id + '">';  
        listItem += '文件:<em>' + file.name + '</em>(' + Math.round(file.size/1024/1024) + ' MB)';  
        listItem += '<span class="progressValue"></span>'  
                  + '<div class="progressBar"><div class="progress"></div></div>'  
                  + '<p class="status" >Pending</p>'  
                  + '</li>';  
        $("#logList").append(listItem);  
        /*$("li#" + file.id + " .cancel").click(function(e) {  
            swfUpload.cancelUpload(file.id);  
            $("li#" + file.id).slideUp('fast');  
        })  */
    //  swfUpload.startUpload();  
    }  
      
    /** 
    * 文件加入上传队列失败时触发,触发原因包括:<br /> 
    * 文件大小超出限制<br /> 
    * 文件类型不符合<br /> 
    * 上传队列数量限制超出等. 
    * @param file 当前文件 
    * @param errorCode 错误代码(参考SWFUpload.QUEUE_ERROR常量) 
    * @param message 错误信息 
    */  
    function fileQueueError(file,errorCode,message) {  
        if (errorCode == SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {  
            alert("每次最多只能有1个文件上传.");  
            return;  
        }  
        if (!queueErrorArray) {  
            queueErrorArray = [];  
        }  
        var errorFile = {  
            file: file,  
            code: errorCode,  
            error: ''  
        };  
        switch (errorCode) {  
        case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:  
            errorFile.error = '文件大小超出限制.';  
            break;  
        case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:  
            errorFile.error = '文件类型受限.';  
            break;  
        case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:  
            errorFile.error = '文件为空文件.';  
            break;  
        default:  
            alert('加载入队列出错.');  
            break;  
        }  
        queueErrorArray.push(errorFile);  
    }  
      
    /** 
    * 选择文件对话框关闭时触发,报告所选文件个数、加入上传队列文件数及上传队列文件总数 
    * @param numSelected 选择的文件数目 
    * @param numQueued 加入队列的文件数目 
    * @param numTotalInQueued 上传文件队列中文件总数 
    */  
    function fileDialogComplete(numSelected,numQueued,numTotalInQueued) {  
        var swfupload = this;  
        if (queueErrorArray && queueErrorArray.length) {  
            var table = $('<table><tr><td>文件</td><td>大小</td></tr></table>');  
            for(var i in queueErrorArray) {  
                var tr = $('<tr></tr>');  
                var info = '<td>' + queueErrorArray[i].file.name + '<span style="color:red">('   
                            + queueErrorArray[i].error + ')</span></td>'  
                            + '<td>' + queueErrorArray[i].file.size + 'bytes</td>';  
                table.append(tr.append(info));  
            }  
            $.ligerDialog.open({  
                width: 500,  
                content: table,  
                title: '文件选择错误提示',  
                buttons: [{  
                    text: '确定',  
                    onclick: function(btn,dialog,index) {  
                        $("#queueStatus").text('选择文件: ' + numSelected + ' / 加入队列文件: ' + numQueued);  
                        swfupload.startUpload();  
                        dialog.close();  
                    }  
                }]  
            });  
            queueErrorArray = [];  
        } else {  
            this.startUpload();  
        }  
    }  
    
    /** 
    * 文件开始上传时触发 
    * @param file 开始上传目标文件 
    */  
    function uploadStart(file) {  
        if (file) {  
            $("#logList li#" + file.id).find('p.status').text('上传中...');  
            $("#logList li#" + file.id).find('p.progressValue').text('0%');  
        }  
    }
    
    /** 
    * 文件上传过程中定时触发,更新进度显示 
    * @param file 上传的文件 
    * @param bytesCompleted 已上传大小 
    * @param bytesTotal 文件总大小 
    */  
    function uploadProgress(file,bytesCompleted,bytesTotal) {  
        var percentage = Math.round((bytesCompleted / bytesTotal) * 100);  
        $("#logList li#" + file.id).find('div.progress').css('width',percentage + '%');  
        $("#logList li#" + file.id).find('span.progressValue').text(percentage + '%');  
    }  
    
    //================================================================================================================
    
	    $("#market_id").combobox({    
		    url: '/market/combobox',   
		    valueField:'id',    
		    textField:'name',
		    required: true,
		    width:122
		}); 
	});
</script>
<form method="post" id="editForm" name="editForm">
	<input type="hidden" name="clientVersion.id" value="${(po.id)!}" id="poid">
	<div id="tt" class="easyui-tabs" style="width: 786px; height: 450px;">
		<div title="版本信息" style="padding: 5px;">
			<table class="tableForm tableCss">
				<tr>
					<th><font color=red>*</font>版本名称</th>
					<td><input type="text" name="clientVersion.version_name" class="easyui-validatebox" value="${(po.version_name)!}" data-options="required:true"></td>
				</tr>
				<tr>	
					<th><font color=red>*</font>版本号</th>
					<td><input type="text" name="clientVersion.version_code" class="easyui-validatebox" value="${(po.version_code)!}" data-options="required:true"></td>
				</tr>
				<tr>
					<th>版本类型</th>
					<td>
						<input name="clientVersion.type" class="easyui-combobox"  value="${(po.type)!0}" 
						data-options="valueField: 'label',textField: 'value',
						data: [{label: '0',value: '个人版'},{label: '1',value: '商户版'}]">
					</td>
					<!-- <th><font color=red>*</font>下载地址</th>
					<td><input type="text" name="clientVersion.download_url" class="easyui-validatebox" value="${(po.download_url)!}" data-options="required:true"></td> -->
				</tr>
				<tr>
					<th><font color=red>*</font>下载地址</th>
					<td colspan="3">
						<div title="安装文件" style="padding:5px;">
							<div class="tableForm datagrid-toolbar" >
								<div style="width:60px;border:1px;">
									<span id="upbtn"></span>
								</div>
								<div id="img_div">
									<#if po?? && po.download_url??>
									<div style='float:left;'>
										<br/><br/>
										<input type="hidden" name="clientVersion.download_url" value="${(po.download_url)!}">
										${(po.download_url)!}
										<br/><br/>
										<a href="#" class="easyui-linkbutton" onclick="javascript:$(this).parent().remove();">删除</a>
									</div>
									</#if>
								</div>
								<p id="queueStatus"></p>
								<ol id="logList"></ol>
							</div>
						</div>
					</td>
				</tr>
			</table>
		</div>
	</div>
</form>